<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px" @submit.native.prevent>
      <el-form-item label="人设名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入配置名称"
          clearable
          @clear="handleQuery"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['human:aiui:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['human:aiui:import']"
        >导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['human:aiui:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-row :gutter="2">
      <div v-for="(item, index) in this.humanConfigList" :key="index" style="margin-top: 20px;">
        <!--左边-->
        <el-col :span="12" v-show="index % 2 == 0">
          <el-card shadow="hover" style="height: 170px">
            <el-col :span="4">
              <div>
                <el-avatar shape="circle" :size="75" :src="item.logoUrl"></el-avatar>
              </div>
            </el-col>
            <el-col :span="20">
              <div>
                <el-col :span="14">
                  <span>{{item.name}}</span>
                  <span v-show="item.status == 0" style="margin-left: 4px">
                    <el-tag
                      size="mini"
                      type="success">
                      启用
                    </el-tag>
                  </span>
                  <span v-show="item.status == 1" style="margin-left: 4px">
                    <el-tag
                      size="mini"
                      type="info">
                      停用
                    </el-tag>
                  </span>
                </el-col>
                <el-col :span="10">
                  <span>
                    <el-button
                      size="mini"
                      type="text"
                      @click="handleDetail(item)"
                      v-hasPermi="['human:aiui:query']"
                    >详情</el-button>
                    <el-button
                      size="mini"
                      type="text"
                      @click="handleUpdate(item)"
                      v-hasPermi="['human:aiui:edit']"
                    >编辑</el-button>
                    <el-button
                      size="mini"
                      type="text"
                      @click="handleDelete(item)"
                      v-hasPermi="['human:aiui:remove']"
                    >删除</el-button>
                    <el-button
                      size="mini"
                      type="text"
                      @click="updateConfigStatus(item)"
                      v-hasPermi="['human:aiui:query']"
                    >
                      <span v-show="item.status == 0">停用</span>
                      <span v-if="item.status == 1">启用</span>
                    </el-button>
                  </span>
                </el-col>
                <div>
                  <el-descriptions>
                    <el-descriptions-item label="人设ID">{{item.uid}}</el-descriptions-item>
                  </el-descriptions>
                  <el-descriptions>
                    <el-descriptions-item label="唤醒名称">{{item.wakeUpName}}</el-descriptions-item>
                    <el-descriptions-item label="发音人">{{item.speakerInfoDto.name}}</el-descriptions-item>
                  </el-descriptions>
                  <el-descriptions>
                    <el-descriptions-item label="开场白">{{item.prologue}}</el-descriptions-item>
                  </el-descriptions>
                </div>
              </div>
            </el-col>
          </el-card>
        </el-col>
        <!--右边-->
        <el-col :span="12" v-show="index % 2 == 1">
          <el-card shadow="hover" style="height: 170px">
            <el-col :span="4">
              <div>
                <el-avatar shape="circle" :size="75" :src="item.logoUrl"></el-avatar>
              </div>
            </el-col>
            <el-col :span="20">
              <div>
                <el-col :span="14">
                  <span>{{item.name}}</span>
                  <span v-show="item.status == 0" style="margin-left: 4px">
                    <el-tag
                      size="mini"
                      type="success">
                      启用
                    </el-tag>
                  </span>
                  <span v-show="item.status == 1" style="margin-left: 4px">
                    <el-tag
                      size="mini"
                      type="info">
                      停用
                    </el-tag>
                  </span>
                </el-col>
                <el-col :span="10">
                  <span>
                    <el-button
                      size="mini"
                      type="text"
                      @click="handleDetail(item)"
                      v-hasPermi="['human:aiui:query']"
                    >详情</el-button>
                    <el-button
                      size="mini"
                      type="text"
                      @click="handleUpdate(item)"
                      v-hasPermi="['human:aiui:edit']"
                    >编辑</el-button>
                    <el-button
                      size="mini"
                      type="text"
                      @click="handleDelete(item)"
                      v-hasPermi="['human:aiui:remove']"
                    >删除</el-button>
                    <el-button
                      size="mini"
                      type="text"
                      @click="updateConfigStatus(item)"
                      v-hasPermi="['human:aiui:query']"
                    >
                      <span v-show="item.status == 0">停用</span>
                      <span v-if="item.status == 1">启用</span>
                    </el-button>
                  </span>
                </el-col>
                <div>
                  <el-descriptions>
                    <el-descriptions-item label="人设ID">{{item.uid}}</el-descriptions-item>
                  </el-descriptions>
                  <el-descriptions>
                    <el-descriptions-item label="唤醒名称">{{item.wakeUpName}}</el-descriptions-item>
                    <el-descriptions-item label="发音人">{{item.speakerInfoDto.name}}</el-descriptions-item>
                  </el-descriptions>
                  <el-descriptions>
                    <el-descriptions-item label="开场白">{{item.prologue}}</el-descriptions-item>
                  </el-descriptions>
                </div>
              </div>
            </el-col>
          </el-card>
        </el-col>
      </div>
    </el-row>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改人设对话框 -->
    <el-dialog :title="title" :visible.sync="isDetailOpen" width="80%"  :before-close="handleClose">
      <!--详情-->
      <div v-show="!isEdit">
        <el-row>
          <el-col :span="2">
            <el-avatar shape="circle" :size="75" :src="form.logoUrl"></el-avatar>
          </el-col>
          <el-col :span="22">
            <div>
              <el-col :span="10">
                <span style="font-weight: bold;font-size: 16px">{{this.form.name}}</span>
                <span v-show="form.status == 0" style="margin-left: 4px">
              <el-tag
                size="mini"
                type="success">
                停用
              </el-tag>
            </span>
                <span v-show="form.status == 1" style="margin-left: 4px">
              <el-tag
                size="mini"
                type="info">
                启用
              </el-tag>
            </span>
              </el-col>
              <el-col :span="12">
              <span style="margin-left: 300px">
                <el-button
                  size="mini"
                  type="primary"
                  @click="handleUpdate(undefined)"
                  v-hasPermi="['human:aiui:edit']"
                >编辑</el-button>
                <el-button
                  @click="handleDelete(null)"
                  size="mini"
                  type="danger"
                  plain
                  v-hasPermi="['human:aiui:remove']"
                >删除</el-button>
                <el-button
                  size="mini"
                  plain
                  @click="updateConfigStatus(undefined)"
                  v-hasPermi="['human:aiui:query']"
                >
                  <span v-show="form.status == 1">停用</span>
                  <span v-show="form.status == 0">启用</span>
                </el-button>
              </span>
              </el-col>
            </div>
          </el-col>
          <el-col :span="16">
            <div style="margin-top: 5px">
              <el-descriptions>
                <el-descriptions-item label="人设ID">{{this.form.uid}}</el-descriptions-item>
                <el-descriptions-item label="唤醒名称">{{this.form.wakeUpName}}</el-descriptions-item>
                <el-descriptions-item label="发音人名称">{{this.form.speakerInfoDto.name}}</el-descriptions-item>
              </el-descriptions>
            </div>
            <div>
              <el-descriptions>
                <el-descriptions-item label="开场白">{{this.form.prologue}}</el-descriptions-item>
              </el-descriptions>
              <div v-for="(item, index) in this.form.questionContentList">
                <el-descriptions>
                  <el-descriptions-item :label="item.name">{{item.content}}</el-descriptions-item>
                </el-descriptions>
              </div>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="1">
            <span>提示词:</span>
          </el-col>
          <el-col :span="22">
            <div style="width: 100%;height:550px; overflow-y: auto;border: 1px solid #666666;margin-left: 15px">
              {{this.form.promptWord}}
            </div>
          </el-col>
        </el-row>
      </div>

      <!--编辑-->
      <div v-show="isEdit">
        <el-row>
          <el-col :span="2">
            <el-avatar shape="circle" :size="75" :src="this.form.logoUrl"></el-avatar>
          </el-col>
          <el-col :span="10">
            <el-upload
              class="upload-template"
              ref="upload"
              :action="uploadUrl"
              :limit="1"
              :show-file-list="false"
              :before-upload="handleBeforeUpload"
              :on-success="handleUploadSuccess"
              :on-error="handleUploadError"
              :headers="headers">
              <el-button size="small"
                         plain>上传图片</el-button>
              <div slot="tip" class="el-upload__tip">建议图片像素为76*76px</div>
            </el-upload>
          </el-col>
          <el-col :span="10">
            <div>
              <el-col :span="12">
                <span style="margin-left: 300px">
                  <el-button
                    size="mini"
                    type="primary"
                    @click="submitForm"
                    v-hasPermi="['human:aiui:edit']"
                  >保存</el-button>
                </span>
              </el-col>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <div style="margin-top: 20px">
            <el-form :model="form" ref="form" :rules="rules" label-width="80px">
              <el-row>
                <el-col :span="5">
                  <el-form-item label="人设名称" prop="name">
                    <el-input type= "text" v-model="form.name"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="5">
                  <el-form-item label="唤醒名称" prop="wakeUpName">
                    <el-input type= "text" v-model="form.wakeUpName"></el-input>
                  </el-form-item>
                  <el-form-item label="新增字段">
                    <el-button @click="addFieldDialog" icon="el-icon-plus" size="small">新增字段</el-button>
                    <el-row v-for="(item, index) in this.fieldList" :key="index" style="margin-top:10px">
                      <el-col :span="18">
                        <el-input type= "text" v-model="item.name" disabled></el-input>
                      </el-col>
                      <el-col :span="4" style="margin-left:8px">
                        <el-button type="info" icon="el-icon-delete" circle size="mini" @click="removeField(index)"></el-button>
                      </el-col>
                    </el-row>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="5">
                  <el-form-item label="发音人" prop="speakerUid">
                    <el-select
                      v-model="form.speakerUid"
                      filterable
                      remote
                      reserve-keyword
                      placeholder="请输入关键词"
                      :remote-method="remoteSearchSpeaker"
                    >
                      <el-option
                        v-for="item in speakerList"
                        :key="item.uid"
                        :label="item.name"
                        :value="item.uid">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="5">
                  <el-form-item label="背景音乐" prop="chatBackgroundMusicUid">
                    <el-select
                      v-model="form.chatBackgroundMusicUid"
                      filterable
                      remote
                      reserve-keyword
                      placeholder="请输入关键词"
                      :remote-method="remoteChatBackgroundMusic">
                      <el-option
                        v-for="item in chatBackgroundMusicList"
                        :key="item.uid"
                        :label="item.name"
                        :value="item.uid">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="15">
                  <el-form-item label="开场白" prop="prologue">
                    <el-input type= "textarea" v-model="form.prologue" :rows="10"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="开场问题">
                    <el-button @click="addQuestion" icon="el-icon-plus" size="small">添加</el-button>
                  </el-form-item>
                  <el-col :span="16">
                    <el-form-item
                      v-for="(item, index) in this.questionContentList"
                      :key="index"
                      required :error="item.rule"
                    >
                      <el-col :span="3">
                        <span>{{item.name}}:</span>
                      </el-col>
                      <el-col :span="6" style="margin-left: 5px">
                        <el-input type= "text"
                                  @blur="checkQuestionContentValid(index)"
                                  v-model="item.content"
                        ></el-input>
                      </el-col>
                      <el-col :span="6">
                        <el-button type="info" icon="el-icon-close" circle @click="removeQuestion(index)" size="mini" style="margin-left: 10px"></el-button>
                      </el-col>
                    </el-form-item>
                  </el-col>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="提示词" prop="promptWord">
                    <el-input type= "textarea" v-model="form.promptWord" :rows="20" :cols="24"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </div>
        </el-row>
        <!--新增字段-->
        <el-dialog :title="'新增字段'" :visible.sync="addField" width="25%"  :before-close="addFieldHandleClose" append-to-body>
          <el-form :model="addFieldForm" :rules="addFieldRules" ref="addFieldForm">
            <el-form-item label="字段名称" :label-width="80" prop="name">
              <el-col :span="8">
                <el-input v-model="addFieldForm.name" autocomplete="off" placeholder="字段名称"></el-input>
              </el-col>
            </el-form-item>
            <el-form-item label="字段属性" :label-width="80" prop="properties">
              <el-select v-model="addFieldForm.properties" placeholder="请选择字段属性">
                <el-option
                  v-for="item in dict.type.properties_type"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="是否必须" :label-width="80" prop="properties">
              <el-radio-group v-model="addFieldForm.required">
                <el-radio :label="0">否</el-radio>
                <el-radio :label="1">是</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer" style="margin-top: -50px">
            <el-button type="primary" @click="submitAddField">确 定</el-button>
            <el-button @click="addFieldHandleClose">取 消</el-button>
          </div>
        </el-dialog>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {listHumanModelManager, insertHumanModelManager, selectHumanModelManager, deleteHumanModelManager, updateHumanModelManagerStatus, updateHumanModelManager} from "@/api/platform/human/human";
import {listChatBackgroundMusic} from "@/api/platform/human/chatBackgroundMusic";
import {listSpeakerInfo} from "@/api/platform/human/speaker";
import {getToken} from "@/utils/auth";
export default {
  name: "HumanConfig",
  dicts: ['properties_type'],
  data() {
    let checkName = (rule, value, callback) => {
      if (!value) {
        return callback(new Error('人设名称不能为空'));
      }
      setTimeout(() => {
        if(value.length > 20){
          callback(new Error('名称必须20个字一下'));
        }else{
          callback();
        }
      }, 1000);
    };

    let checkPrologue = (rule, value, callback) => {
      if (!value) {
        return callback(new Error('开场白不能为空'));
      }
      setTimeout(() => {
        if(value.length >= 100){
          callback(new Error('开场白100字以内'));
        }else{
          callback();
        }
      }, 1000);
    };

    let checkWakeUpName = (rule, value, callback) => {
      if (!value) {
        return callback(new Error('唤醒名称不能为空'));
      }
      setTimeout(() => {
        if(value.length > 5){
          callback(new Error('唤醒名称必须5个字以下'));
        }else{
          callback();
        }
      }, 1000);
    };
    return {
      uploadUrl: process.env.VUE_APP_BASE_API + "/system/file/upload", // 上传的图片服务器地址
      headers: {
        Authorization: "Bearer " + getToken()
      },
      fieldList: [],
      addField: false,
      questionContentList: [],
      //是否必填
      isEdit: false,
      operationType: true,
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      //发音人
      speakerList:[],
      chatBackgroundMusicList: [],
      humanConfigList: [],
      // 总条数
      total: 0,
      // 弹出层标题
      title: "",
      detailOpen: false,
      //是否显示详情的弹框
      isDetailOpen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      //添加字段的数据内容
      addFieldForm: {},
      // 表单参数
      form: {
        speakerInfoDto: {
          name: ''
        }
      },
      rules: {
        name: [
          { validator: checkName, trigger: "blur" },
          { required: true, message: "人设名称不能为空", trigger: "blur" }
        ],
        wakeUpName: [
          { validator: checkWakeUpName, trigger: "blur" },
          { required: true, message: "唤醒名称不能为空", trigger: "blur" }
        ],
        prologue: [
          { validator: checkPrologue, trigger: "blur" },
          { required: true, message: "开场白不能为空", trigger: "blur" }
        ],
        speakerUid: [
          { required: true, message: "发音人不能为空", trigger: "blur" }
        ],
        chatBackgroundMusicUid: [
          { required: true, message: "背景音乐不能为空", trigger: "blur" }
        ]
      },
      addFieldRules: {
        name: [
          { required: true, message: "字段名称不能为空", trigger: "blur" }
        ],
        properties: [
          { required: true, message: "属性不能为空", trigger: "blur" }
        ],
        required: [
          { required: true, message: "是否必须不能为空", trigger: "blur" }
        ],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询模板列表 */
    getList() {
      this.loading = true;
      listHumanModelManager(this.queryParams).then(response => {
        this.humanConfigList = response.rows;
        this.total = response.total;
        this.loading = false;
      })
    },
    // 上传前校检格式和大小
    handleBeforeUpload(file) {
      const type = ["image/jpeg", "image/jpg", "image/png"];
      const isJPG = type.includes(file.type);
      // 检验文件格式
      if (!isJPG) {
        this.$message.error(`文件格式错误!`);
        return false;
      }
      // 校检文件大小
      if (this.fileSize) {
        const isLt = (file.size / 1024 / 1024 < this.fileSize.default);
        if (!isLt) {
          this.$message.error(`上传文件大小不能超过 ${this.fileSize} MB!`);
          return false;
        }
      }
      return true;
    },
    handleUploadSuccess(res, file) {
      // 如果上传成功
      if (res.code == 200) {
        this.form.fileUid = res.data.uid;
        this.form.logoUrl = res.data.url;
        this.$message.success("上传成功");
        this.$refs.upload.clearFiles()

      } else {
        this.$message.error("上传失败");
      }
    },
    handleUploadError() {
      this.$message.error("上传失败");
    },

    remoteSearchSpeaker(inputContent){
      let data ={}
      data.name = inputContent;
      listSpeakerInfo(data).then(response => {
        if(response.code == 200){
          this.speakerList = response.rows;
        }
      })
    },
    remoteChatBackgroundMusic(inputContent){
      let data ={}
      data.name = inputContent;
      listChatBackgroundMusic(data).then(response => {
        this.chatBackgroundMusicList = response.rows;
        this.total = response.total;
      })
    },
    addFieldDialog(){
      //必须一个个添加，如果列表中存在大于的
      if(this.fieldList.length > 0){
        let data = this.fieldList[this.fieldList.length - 1];
        if(data.name == undefined || data.name == ''){
          return;
        }
      }
      if(this.fieldList.length > 10){
        this.$modal.msgError("字段最大为10个");
        return;
      }
      this.addField= true
      this.addFieldForm= {};
      let obj = {required : 0};
      this.addFieldForm = obj
    },
    submitAddField(){
      this.$refs["addFieldForm"].validate(valid => {
        if (valid) {
          this.fieldList.push(this.addFieldForm)
          this.addField= false;
        }
      })
    },
    //删除添加字段
    removeField(index){
      this.fieldList.splice(index, 1);
    },
    addFieldHandleClose(){
      this.addFieldForm= {}
      this.addField= false;
    },
    handleClose(){
      this.cancel()
    },
    removeQuestion(index){
      this.questionContentList.splice(index, 1);
      if(this.questionContentList.length > 0){
        let newQuestionContentList=[];
        for(let i =0;i <this.questionContentList.length; i++){
          let data={}
          data.name = "开场问题" + (i + 1);
          data.content = this.questionContentList[i].content;
          data.rule=this.questionContentList[i].rule;
          newQuestionContentList.push(data);
        }
        this.questionContentList = newQuestionContentList;
      }
    },
    addQuestion(){
      let data ={}
      let index = this.questionContentList.length;
      if(index > 2){
        this.$modal.msgError("最大只能三个问题");
        return;
      }
      data.name = "开场问题" + (index + 1);
      data.content = null;
      data.rule='';
      this.questionContentList.push(data)
    },
    //修改配置状态
    updateConfigStatus(row){
      let message = ""
      let data = {};
      if(row == undefined || row == null){
        data.uid = this.form.uid;
        data.name = this.form.name;
        data.status = this.form.status;
      }else{
        data.uid = row.uid;
        data.name = row.name;
        data.status = row.status;
      }
      if(data.status == 0){
        message = "<div>确定要启用应用: <span>" + data.name + " ?</span></div>"+
          "<span style='margin-top: 20px'>应用ID:</span> &nbsp;&nbsp;&nbsp;" + data.uid
      }else{
        message = "<div>确定要停用应用: <span>" + data.name + " ?</span></div>"+
          "<span style='margin-top: 20px'>应用ID:</span> &nbsp;&nbsp;&nbsp;" + data.uid
      }
      this.$modal.confirm(message).then(function() {
        return updateHumanModelManagerStatus(data);
      }).then(() => {
        if (data.status == 0) {
          this.$modal.msgWarning("已停用");
        } else {
          this.$modal.msgSuccess("已启用");
        }
        if(row == undefined){
          let row ={};
          row.uid = this.form.uid;
          this.handleDetail(row);
        }else{
          this.getList();
        }
      }).catch(() => {});
    },
    // 取消按钮
    cancel() {
      this.fieldList = []
      this.addFieldForm = {}
      this.isDetailOpen = false;
      this.isEdit=false
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {};
      this.form.speakerInfoDto ={}
      this.isDetailOpen = false;
      this.isEdit = false;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.title = "添加人设";
      this.form.status = 0
      this.isDetailOpen = true
      this.isEdit=true;
      this.speakerList =[]
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.speakerList=[];
      this.chatBackgroundMusicList=[];
      this.isDetailOpen=true;
      this.isEdit = true;
      this.title = "修改人设信息";
      let data = {};
      if(row == undefined || row == null){
        data.uid = this.form.uid;
        data.name = this.form.name;
        data.status = this.form.status;
      }else{
        data.uid = row.uid;
        data.name = row.name;
        data.status = row.status;
      }
      this.selectDetail(data);
    },
    checkQuestionContentValid(index){
      if(!this.questionContentList[index].content.trim()){
        this.questionContentList[index].rule = '非表单校验不能为空'
        return false
      }else{
        this.questionContentList[index].rule = ''
        return true
      }
    },
    handleDetail(row){
      this.title="人设详情"
      this.selectDetail(row);
    },
    //查询详情
    selectDetail(row){
      selectHumanModelManager(row.uid).then(response =>{
        if(response.code == 200){
          this.form = response.data
          this.fieldList =[];
          this.speakerList =[];
          this.isDetailOpen = true
          if(this.form.speakerInfoDto != null){
            this.speakerList.push(this.form.speakerInfoDto);
          }
          if(this.form.chatBackgroundMusicDto != null){
            this.chatBackgroundMusicList.push(this.form.chatBackgroundMusicDto);
          }
          if(this.form.questionContentList != null || this.form.questionContentList.length >0){
            this.questionContentList = this.form.questionContentList;
          }

          if(this.form.fieldList != null && this.form.fieldList.length > 0){
            this.fieldList =this.form.fieldList;
          }
        }
      })
    },

    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          //问题的处理
          let resultQuestionList =[];
          if(this.questionContentList.length > 0){
            for(let i =0; i<this.questionContentList.length; i++){
              if(this.questionContentList[i].content == '' || this.questionContentList[i].content == null){
                continue;
              }
              let data={}
              data.name = this.questionContentList[i].name;
              data.content = this.questionContentList[i].content;
              resultQuestionList.push(data)
            }
          }
          this.form.questionContentList = resultQuestionList;
          this.form.fieldList = this.fieldList;
          if (this.form.uid == undefined) {
            insertHumanModelManager(this.form).then(response => {
              this.reset()
              this.$modal.msgSuccess("添加成功");
              this.getList();
            })
          }else{
            let data = this.form;
            data.status = null
            //提示
            const message = "<div>确定要修改应用信息？</div>"
            this.$modal.confirm(message).then(function() {
              return updateHumanModelManager(data);
            }).then(() => {
              this.reset()
              this.$modal.msgSuccess("修改成功");
              this.isDetailOpen=false,
                this.getList();
            })
          }
        }
      })
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      let data ={}
      if(row == undefined){
        data.uid = this.form.uid;
        data.name = this.form.name;
      }else{
        data.uid = row.uid;
        data.name = row.name;
      }
      //提示
      const message = "<div>确定要删除应用: <span>" + data.name + " ?</span></div>"+
        "<span style='margin-top: 20px'>应用ID:</span> &nbsp;&nbsp;&nbsp;" + data.uid
      this.$modal.confirm(message).then(function() {
        return deleteHumanModelManager(data);
      }).then(() => {
        this.isDetailOpen=false;
        this.isEdit =false;
        this.$modal.msgSuccess("删除成功");
        this.getList()
      })
    },
  }
};
</script>
<style scoped>
/deep/ .el-textarea__inner {
  resize: none;
}
.detail_name{
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
</style>
